package com.example.dllo.my36kr.news.video;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.MediaController;
import android.widget.VideoView;

import com.example.dllo.my36kr.R;

/**
 * Created by dllo on 16/8/25.
 */
public class VideoAdapter extends BaseAdapter {
    Context mContext;
    VideoBean videoBean;
    private RecyclerView.ViewHolder viewHolder;
    public void setVideoBean(VideoBean videoBean) {
        this.videoBean = videoBean;

    }
    public VideoAdapter(Context mContext) {
        this.mContext = mContext;

    }

    @Override
    public int getCount() {
        return videoBean.getData().getData().size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        Video video= null;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.video,parent,false);
            video = new Video(convertView);
            convertView.setTag(video);
        }else {
            video = (Video) convertView.getTag();
        }
        video.videoView.setMediaController(new MediaController(mContext));
        video.videoView.setVideoURI(Uri.parse(videoBean.getData().getData().get(position).getTv().getVideoSource()));
        video.videoView.requestFocus();

//        final ViewHolers finalViewHolers = viewHolers;
//        viewHolers.imageView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if(currentViewHolders!=null){
//                    currentViewHolders.imageView.setVisibility(View.VISIBLE);
//                    currentViewHolders.tvKETVTitle.setVisibility(View.VISIBLE);
//                    currentViewHolders.vvwMp.pause();
//                }
//                finalViewHolers.vvwMp.start();
//                finalViewHolers.imageView.setVisibility(View.GONE);
//                finalViewHolers.tvKETVTitle.setVisibility(View.GONE);
//                currentViewHolders = finalViewHolers;
//            }
//        });

        return convertView;

    }
    public class Video{
        VideoView videoView;

        public Video(View view) {
            videoView = (VideoView) view.findViewById(R.id.videoView);


        }
    }
}
